import requests

from bs4 import BeautifulSoup

url ='https://movie.douban.com/top250'

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}

response = requests.get(url,headers=headers)
html = response.content.decode()
soup = BeautifulSoup(response.content.decode(),'lxml')
r1 = soup.find_all('div',{'class': 'info'})
list_data = []
for e in r1:
    name = e.select('span')[0].string
    url = e.find('a')['href']
    grade =e.find('div',{'class':'star'}).select('span')[1].string
    data={'标题':name,'评分':grade,'详情链接':url}
    list_data.append(data)
with open('douban1.txt','a',encoding='utf-8') as f:
    f.write(list_data.__str__()+"\n")
